package com.example.demo.utils;

import com.example.demo.function.BranchHandle;
import com.example.demo.function.ThrowExceptionFunction;

/**
 * @auther: Wyz
 * @date: 2021/11/30 10:37
 * @return
 */
public class VUtils {

    private VUtils(){

    }


    /**
     *  如果参数为true抛出异常
     *
     * @param b
     * @return com.example.demo.func.ThrowExceptionFunction
     **/
    public static ThrowExceptionFunction isTure(boolean b){
        return errorMessage -> {
            if (b){
                throw new RuntimeException(errorMessage);
            }
        };
    }



    /**
     * 参数为true或false时，分别进行不同的操作
     *
     * @param b
     * @return com.example.demo.func.BranchHandle
     **/
    public static BranchHandle isTureOrFalse(boolean b){
        return (trueHandle, falseHandle) -> {
            if (b){
                trueHandle.run();
            } else {
                falseHandle.run();
            }
        };
    }
}
